﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace TetrisByPhillAndRomaCorp
{
   public class GameEngine
    {
       private TickGenerator tickGenerator = new TickGenerator();
       private ChangePositionR change = new ChangePositionR();
       private   Field f = new Field(25, 25);
       private GamrRender gr = new GamrRender();
       private Thread secondThread;



       public void Start()
       {
          // secondThread.Start();
           secondThread = new Thread(ChengePosition);
           secondThread.IsBackground = true;
           secondThread.Start();



           tickGenerator.Tick += tickGenerator_Tick;
           tickGenerator.Start();
           secondThread.Start();
          
       }

       void ChengePosition()
       {
           while (true)
           {
               Thread.Sleep(0);
               change.Change();
           }
       }
      
       
       
       
    
       
       void tickGenerator_Tick(object sender, EventArgs e)
       {
          
          // change.Change();
          // secondThread.IsBackground = true;

           gr.RenderField(f);
           Console.Beep();
           
           //secondThread.Start();
       }

    }
}
